<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="/views/common/header.jsp" %>
<form action="" method="get">
<div class="form-group clearfix">
  <div class="col-sm-9">
    <input type="hidden" name="type" value="${type }">
    <input class="form-control input-sm" name="search" placeholder="搜索标题关键字..." value="${key_word}">
  </div>                          
  <div class="col-sm-3">
    <button class="btn pull-right btn-block btn-sm">搜索</button>
  </div>                          
</div>
</form>
<div class="box">
  <div class="box-header">
    <div class="box-tools">
      <ul class="pagination pagination-sm no-margin pull-right">
        <c:set var="currentPage" value="${res_list.pageNumber}" />
        <c:set var="totalPage" value="${res_list.totalPage}" />
        <c:set var="actionUrl" value="/restype/list" />
        <c:choose>
        <c:when test="${key_word != null && key_word !=\"\" }">
        <c:set var="urlParas" value="search=${key_word }" />
        </c:when>
        <c:otherwise>
        <c:set var="urlParas" value="" />
        </c:otherwise>
        </c:choose>
        <c:set var="in_table" value="1" />
        <%@ include file="/views/common/_paginate.jsp" %>
      </ul>
    </div>
  </div><!-- /.box-header -->
  <div class="box-body no-padding">
    <table class="table">
      <tbody><tr>
        <th>ID</th>
        <th>资源</th>
        <th>下载权限</th>
        <th>操作</th>
      </tr>
      <c:forEach var="res" items="${res_list.list }">
      <tr>
        <td>${res.id }.</td>
        <td><a href="/resource/detail/${res.id }">${res.title }</a></td>
        <td>
            <c:choose>
            <c:when test="${res.downtype == 1 }">
            <span class="text-red">登录后才可下载</span>
            </c:when>
            <c:otherwise>
            <span class="text-green">游客可下载</span>
            </c:otherwise>
            </c:choose>
        </td>
        <td>
            <a href="/resource/detail/${res.id }">查看</a>
            <c:choose>
            <c:when test="${res.downtype == 1 && is_login == 0 }">
             | <a href="/user/Login">登录</a>
            </c:when>
            <c:otherwise>
             | <a href="/resource/resDownload/${res.id }">下载</a>
            </c:otherwise>
            </c:choose>
            <c:if test="${is_admin == 1 }">
             <!-- | <a href="/resource/edit/?id=${res.id }">修改</a> -->
             | <a class="text-red" href="javascript:doDelete(${res.id })">删除</a>
            </c:if>
        </td>
      </tr>
      </c:forEach>
    </tbody></table>
    </div>
  </div><!-- /.box-body -->
<c:set var="in_table" value="0" />
<%@ include file="/views/common/_paginate.jsp" %>
<script>
function doDelete(id)
{
	swal({
		title: "Are you sure?",
		text: "Your will not be able to recover this imaginary file!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: "#DD6B55",
		confirmButtonText: "Yes, delete it!",
		cancelButtonText: "No, cancel plx!",
		closeOnConfirm: false,
		closeOnCancel: false 
	}, function (isConfirm){
		if (isConfirm) {
			$.ajax({
		        'data': {'id':id},
		        'dataType': 'JSON',
		        'url': '/restype/delete',
		        'type': 'post',
		        'success': function (ret){
		            if (parseInt(ret.code) != 200)
		            {
		                swal('删除失败', ret.msg, 'error');
		                return false;
		            }
		            window.location.reload()
		        }
		    })
		} else {
		    swal("Cancelled", "Your imaginary file is safe :)", "error");
		} 
	})
	
}
</script>

<%@ include file="/views/common/footer.jsp" %>